package Dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.mysql.cj.protocol.Resultset;

import Dao.UserDao;
import Domain.User;

public class UserDaoImpl implements UserDao{

	@Override
	public void DeleteUser(User user) {
		String sql="delete * from user where id=?";
		Connection conn=util.JDBC.getConnection();
		PreparedStatement ps=null;
		try {
			ps=conn.prepareStatement(sql);
			ps.setInt(0, user.getId());
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public List<User> AddUesr() {
		List<User> users=new ArrayList<User>();
		String sql="select * from user";
		Connection conn=util.JDBC.getConnection();
		PreparedStatement ps=null;
		try {
			ps=conn.prepareStatement(sql);
			ResultSet rs=ps.executeQuery();
			while(rs.next()) {
				User user=new User();
				user.setId(rs.getInt("id"));
				user.setPassword(rs.getString("password"));
				user.setUsername(rs.getString("username"));
				System.out.println(user.getUsername());
				users.add(user);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return users;
	}
}
